<template>
  <div class="pages-article-classify">
    <page-cover
      bg="https://dongping-blog.oss-cn-hangzhou.aliyuncs.com/systemImage/3f1e6834569a40faae5bf6d1e089826d.png"
    >
      <div class="title">归档</div>
      <p>
        <span>分类 {{ classifyTotal }}</span> ·
        <span>文章 {{ articleStatistics.articleNum }}</span> ·
        <span>原创 {{ articleStatistics.originalNum }}</span>
      </p></page-cover
    >
    <main>
      <div class="list">
        <div
          v-for="(item, index) in classifyList"
          :key="index"
          @click="
            $router.push({
              name: 'classifyDetail',
              params: { id: item.articleClassifyId },
            })
          "
          :style="{
            'background-image': `url(${item.coverImg})`,
          }"
          class="item"
        >
          <div class="text">
            <p>{{ item.name }}</p>
            <p>{{ item.articleNum }}篇笔记</p>
          </div>
        </div>
      </div>
    </main>
  </div>
</template>

<script>
import pageCover from "@/components/page-cover/page-cover";
export default {
  name: "WorkspaceJsonNote",
  components: {
    pageCover,
  },
  data() {
    return {
      classifyList: [],
      classifyTotal: 0,
      articleStatistics: {},
    };
  },

  mounted() {
    this.getClassifyList();
    this.getArticleStatistics();
  },

  methods: {
    // 获取分类列表
    getClassifyList() {
      this.$http("getClassifyList", { sort: 1 }).then((res) => {
        this.classifyList = res.data.lists;

        this.classifyTotal = res.data.total;
      });
    },
    // 获取文章统计数据
    getArticleStatistics() {
      this.$http("getArticleStatistics").then((res) => {
        this.articleStatistics = res.data;
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.pages-article-classify {
  cursor: pointer;
}

.cover {
  .title {
    font-size: 30px;
    font-weight: 600;
  }
  p {
    font-size: 16px;
    opacity: 0.8;
    margin-top: 5px;
    span {
      margin: 0 5px;
    }
  }
}

main {
  max-width: 1100px;
  margin: auto;
  align-items: flex-start;
  margin-top: -80px;
  position: relative;
  z-index: 1;
  padding: 0 10px;
  .list {
    min-height: 80vh;
    background: #fff;
    border-radius: 6px;
    box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.07);
    padding: 20px 10px;
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
    justify-content: center;
    .item {
      width: 220px;
      height: 120px;
      border-radius: 6px;
      background: #f5f5f5;
      display: flex;
      justify-content: center;
      align-items: center;
      position: relative;
      overflow: hidden;
      background-position: center center;
      background-size: cover;
      background-repeat: no-repeat;
      margin: 5px;
      p {
        color: #fff;
        position: relative;
        z-index: 2;
        text-align: center;
        &:nth-child(1) {
          font-weight: 600;
          @include main-text-hidden(1);
        }
        &:nth-child(2) {
          font-size: 14px;
          margin-top: 2px;
          opacity: 0.8;
        }
      }
      &::before {
        content: "";
        width: 100%;
        height: 100%;
        position: absolute;
        top: 0;
        left: 0;
        background-color: rgba(0, 0, 0, 0.5);
      }
    }
  }
}

@media (max-width: 750px) {
  .item {
    width: 165px !important;
    height: 110px !important;
  }
}
@media (max-width: 550px) {
  .item {
    width: 155px !important;
    height: 100px !important;
  }
}
</style>
